home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Information / Mac Programming Secrets 1.0.1 / Chapter 07 / Standard Stuff.c < prev    next >
C/C++ Source or Header  |  1992-05-19  |  20KB  |  686 lines

  1. #include "Standard Stuff.h"
  2. #include "Neat Stuff.h"
  3. #include "Traps.h"
  4.  
  5. /*******************************************************************************
  6.  
  7.     The “g” prefix is used to emphasize that a variable is global.
  8.  
  9. *******************************************************************************/
  10.  
  11. SysEnvRec    gMac;                /*    gMac is used to hold the result of a
  12.                                     SysEnvirons call. This makes it convenient
  13.                                     for any routine to check the environment. */
  14.  
  15. Boolean        gQuit;                /*    We set this to TRUE when the user selects
  16.                                     Quit from the File menu. Our main event
  17.                                     loop exists when gQuit is TRUE. */
  18.  
  19. Boolean        gInBackground;        /*    gInBackground is maintained by our osEvent
  20.                                     handling routines. Any part of the program
  21.                                     can check it to find out if it is currently
  22.                                     in the background. */
  23.  
  24.  
  25. /*******************************************************************************
  26.  
  27.     Define HiWrd and LoWrd macros for efficiency.
  28.  
  29. *******************************************************************************/
  30.  
  31. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  32. #define LoWrd(aLong)    ((aLong) & 0xFFFF)
  33.  
  34.  
  35. /*******************************************************************************
  36.  
  37.     main
  38.  
  39.     Entry point for our program. We initialize the toolbox, make sure we are
  40.     running on a sufficiently studly machine, and put up the menubar. Finally,
  41.     we start polling for events and handling them by entering our main event
  42.     loop.
  43.  
  44. *******************************************************************************/
  45. main()
  46. {
  47.     /*    If you have stack requirements that differ from the default,
  48.         then you could use SetApplLimit to increase StackSpace at
  49.         this point, before calling MaxApplZone. */
  50.  
  51.     MaxApplZone();                    /* Expand the heap so code segments load
  52.                                        at the top */
  53.     InitToolbox();                    /* Initialize the program */
  54.     MainEventLoop();                /* Call the main event loop */
  55. }
  56.  
  57.  
  58. /*******************************************************************************
  59.  
  60.     InitToolbox
  61.  
  62.     Set up the whole world, including global variables, Toolbox managers, and
  63.     menus.
  64.  
  65. *******************************************************************************/
  66. void InitToolbox()
  67. {
  68.     Handle        menuBar;
  69.     EventRecord event;
  70.     short        count;
  71.  
  72.     gInBackground = FALSE;
  73.     gQuit = FALSE;
  74.  
  75.     InitGraf((Ptr) &qd.thePort);
  76.     InitFonts();
  77.     InitWindows();
  78.     InitMenus();
  79.     TEInit();
  80.     InitDialogs(NIL);
  81.     InitCursor();
  82.  
  83.     /*    This next bit of code waits until MultiFinder brings our application
  84.         to the front. This gives us a better effect if we open a window at
  85.         startup. */
  86.  
  87.     for (count = 1; count <= 3; ++count)
  88.         EventAvail(everyEvent, &event);
  89.  
  90.     SysEnvirons(curSysEnvVers, &gMac);
  91.  
  92.     if (gMac.machineType < 0)
  93.         DeathAlert(errWimpyROMs);
  94.  
  95.     if (gMac.systemVersion < 0x0600)
  96.         DeathAlert(errWimpySystem);
  97.  
  98.     if (!TrapExists(_WaitNextEvent))
  99.         DeathAlert(errWeirdSystem);
  100.  
  101.     menuBar = GetNewMBar(rMenuBar);            /* Read menus into menu bar */
  102.     if ( menuBar == NIL )
  103.          DeathAlert(errNoMenuBar);
  104.     SetMenuBar(menuBar);                    /* Install menus */
  105.     DisposHandle(menuBar);
  106.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* Add DA names to Apple menu */
  107.     AdjustMenus();
  108.     DrawMenuBar();
  109. }
  110.  
  111.  
  112. /*******************************************************************************
  113.  
  114.     MainEventLoop
  115.  
  116.     Get events forever, and handle them by calling HandleEvent. First, call
  117.     DoAdjustCursor to set our cursor shape, and to set the cursor region. We
  118.     then call WaitNextEvent() to get the event. This is OK, because we know
  119.     we’re running on System 6.0 or later by this time. If we got an event, we
  120.     handle it by calling HandleEvent(). But before doing that, we call
  121.     DoAdjustCursor again in case our application had fallen asleep under
  122.     MultiFinder.
  123.  
  124. *******************************************************************************/
  125. void MainEventLoop()
  126. {
  127.     RgnHandle    cursorRgn;
  128.     Boolean        gotEvent;
  129.     EventRecord    event;
  130.     Point        mouse;
  131.  
  132.     cursorRgn = NIL;
  133.     while ( !gQuit ) {
  134.         gotEvent = WaitNextEvent(everyEvent, &event, MAXLONG, cursorRgn);
  135.         if ( gotEvent ) {
  136.             HandleEvent(&event);
  137.         }
  138.     }
  139. }
  140.  
  141.  
  142. /*******************************************************************************
  143.  
  144.     HandleEvent
  145.  
  146.     Do the right thing for an event. Determine what kind of event it is, and
  147.     call the appropriate routines.
  148.  
  149. *******************************************************************************/
  150. void HandleEvent(EventRecord *event)
  151. {
  152.     switch ( event->what ) {
  153.         case mouseDown:
  154.             HandleMouseDown(event);
  155.             break;
  156.         case keyDown:
  157.         case autoKey:
  158.             HandleKeyPress(event);
  159.             break;
  160.         case activateEvt:
  161.             HandleActivate(event);
  162.             break;
  163.         case updateEvt:
  164.             HandleUpdate(event);
  165.             break;
  166.         case diskEvt:
  167.             HandleDiskInsert(event);
  168.             break;
  169.         case osEvt:
  170.             HandleOSEvent(event);
  171.             break;
  172.     }
  173. }
  174.  
  175.  
  176. /*******************************************************************************
  177.  
  178.     HandleActivate
  179.  
  180.     This is called when a window is activated or deactivated. In this sample,
  181.     the Window Manager’s handling of activate and deactivate events is
  182.     sufficient. Other applications may have TextEdit records, controls, lists,
  183.     etc., to activate/deactivate.
  184.  
  185. *******************************************************************************/
  186. void HandleActivate(EventRecord *event)
  187. {
  188.     WindowPtr    theWindow;
  189.     Boolean        becomingActive;
  190.  
  191.     theWindow = (WindowPtr) event->message;
  192.     becomingActive = (event->modifiers & activeFlag) != 0;
  193.     if ( IsAppWindow(theWindow) ) {
  194.         DrawGrowIcon(theWindow);
  195.         DoActivateWindow(theWindow, becomingActive);                /* +++ */
  196.     }
  197. }
  198.  
  199.  
  200. /*******************************************************************************
  201.  
  202.     HandleDiskInsert
  203.  
  204.     Called when we get a disk inserted event. Check the upper word of the
  205.     event message; if it’s non-zero, then a bad disk was inserted, and it
  206.     needs to be formatted.
  207.  
  208. *******************************************************************************/
  209. void HandleDiskInsert(EventRecord *event)
  210. {
  211.     Point    aPoint = {100, 100};
  212.  
  213.     if ( HiWrd(event->message) != noErr ) {
  214.         (void) DIBadMount(aPoint, event->message);
  215.     }
  216. }
  217.  
  218.  
  219. /*******************************************************************************
  220.  
  221.     HandleKeyPress
  222.  
  223.     The user pressed a key. What are you going to do about it?
  224.  
  225. *******************************************************************************/
  226. void HandleKeyPress(EventRecord *event)
  227. {
  228.     char    key;
  229.  
  230.     key = event->message & charCodeMask;
  231.     if ( event->modifiers & cmdKey ) {        /* Command key down? */
  232.         AdjustMenus();                        /* Enable/disable/check menu items properly */
  233.         HandleMenuCommand(MenuKey(key));
  234.     } else {
  235.         /* DoKeyPress(event) */;
  236.     }
  237. }
  238.  
  239.  
  240. /*******************************************************************************
  241.  
  242.     HandleMouseDown
  243.  
  244.     Called to handle mouse clicks. The user could have clicked anywhere, so
  245.     let’s first find out where by calling FindWindow. That returns a number
  246.     indicating where in the screen the mouse was clicked. “switch” on that
  247.     number and call the appropriate routine.
  248.  
  249. *******************************************************************************/
  250. void HandleMouseDown(EventRecord *event)
  251. {
  252.     long        newSize;
  253.     Rect        growRect;
  254.     WindowPtr    theWindow;
  255.     short        part = FindWindow(event->where, &theWindow);
  256.  
  257.     switch ( part ) {
  258.         case inMenuBar:                /* Process a mouse menu command (if any) */
  259.             AdjustMenus();
  260.             HandleMenuCommand(MenuSelect(event->where));
  261.             break;
  262.         case inSysWindow:            /* Let the system handle the mouseDown */
  263.             SystemClick(event, theWindow);
  264.             break;
  265.         case inContent:
  266.             if ( theWindow != FrontWindow() )
  267.                 SelectWindow(theWindow);
  268.             else
  269.                 /* DoContentClick(event, theWindow) */;
  270.             break;
  271.         case inDrag:                /* Pass screenBits.bounds to get all gDevices */
  272.             DragWindow(theWindow, event->where, &qd.screenBits.bounds);
  273.             break;
  274.         case inGrow:
  275.             growRect = qd.screenBits.bounds;
  276.             growRect.top = growRect.left = 80;        /* Arbitrary minimum size. */
  277.             newSize = GrowWindow(theWindow, event->where, &growRect);
  278.             if (newSize != 0) {
  279.                 InvalidateScrollbars(theWindow);
  280.                 SizeWindow(theWindow, LoWrd(newSize), HiWrd(newSize), TRUE);
  281.                 InvalidateScrollbars(theWindow);
  282.             }
  283.             break;
  284.         case inGoAway:
  285.             if (TrackGoAway(theWindow, event->where))  {
  286.                 CloseAnyWindow(theWindow);
  287.             }
  288.             break;
  289.         case inZoomIn:
  290.         case inZoomOut:
  291.             if (TrackBox(theWindow, event->where, part)) {
  292.                 SetPort(theWindow);
  293.                 EraseRect(&theWindow->portRect);
  294.                 DoZoomWindow(theWindow, part, TRUE);                /* +++ */
  295.                 InvalRect(&theWindow->portRect);
  296.             }
  297.             break;
  298.     }
  299. }
  300.  
  301.  
  302. /*******************************************************************************
  303.  
  304.     HandleOSEvent
  305.  
  306.     Deal with OSEvents (formerly, app4Events). These are message that
  307.     MultiFinder -- known as the Process Manager under System 7.0 -- sends to
  308.     us. Here, we deal with suspend and resume message.
  309.  
  310. *******************************************************************************/
  311. void HandleOSEvent(EventRecord *event)
  312. {
  313.     switch ((event->message >> 24) & 0x00FF) {        /* High byte of message */
  314.         case suspendResumeMessage:
  315.  
  316.             /*    In our SIZE resource, we say that we are MultiFinder aware.
  317.                 This means that we take on the responsibility of activating
  318.                 and deactivating our own windows on suspend/resume events. */
  319.  
  320.             gInBackground = (event->message & resumeFlag) == 0;
  321.             if (FrontWindow()) {
  322.                 DrawGrowIcon(FrontWindow());
  323.                 DoActivateWindow(FrontWindow(), !gInBackground);    /* +++ */
  324.             }
  325.             break;
  326.         case mouseMovedMessage:
  327.             break;
  328.     }
  329. }
  330.  
  331.  
  332. /*******************************************************************************
  333.  
  334.     HandleUpdate
  335.  
  336.     This is called when an update event is received for a window. It calls
  337.     DoUpdateWindow to draw the contents of an application window. As an
  338.     efficiency measure that does not have to be followed, it calls the drawing
  339.     routine only if the visRgn is non-empty. This will handle situations where
  340.     calculations for drawing or drawing itself is very time-consuming.
  341.  
  342. *******************************************************************************/
  343. void HandleUpdate(EventRecord *event)
  344. {
  345.     WindowPtr    theWindow = (WindowPtr) event->message;
  346.     if ( IsAppWindow(theWindow) ) {
  347.         BeginUpdate(theWindow);                /* This sets up the visRgn */
  348.         if (!EmptyRgn(theWindow->visRgn)) {    /* Draw if updating needs to be done */
  349.             SetPort(theWindow);
  350.             EraseRgn(theWindow->visRgn);
  351.             /* DoUpdateWindow(event) */;
  352.             DrawGrowIcon(theWindow);
  353.         }
  354.         EndUpdate(theWindow);
  355.     }
  356. }
  357.  
  358.  
  359. /*******************************************************************************
  360.  
  361.     AdjustMenus
  362.  
  363.     Enable and disable menus based on the current state. The user can only
  364.     select enabled menu items. We set up all the menu items before calling
  365.     MenuSelect or MenuKey, since these are the only times that a menu item can
  366.     be selected. Note that MenuSelect is also the only time the user will see
  367.     menu items. This approach to deciding what enable/disable state a menu
  368.     item has the advantage of concentrating all the decision-making in one
  369.     routine, as opposed to being spread throughout the application. Other
  370.     application designs may take a different approach that is just as valid.
  371.  
  372. *******************************************************************************/
  373. void AdjustMenus()
  374. {
  375.     WindowPtr    window;
  376.     MenuHandle    menu;
  377.  
  378.     window = FrontWindow();
  379.  
  380.     menu = GetMHandle(mFile);
  381.     if ( window != NIL )
  382.         EnableItem(menu, iClose);
  383.     else
  384.         DisableItem(menu, iClose);
  385.  
  386.     menu = GetMHandle(mEdit);
  387.     if ( IsDAWindow(window) ) {        /* A desk accessory might need the edit menu… */
  388.         EnableItem(menu, iUndo);
  389.         EnableItem(menu, iCut);
  390.         EnableItem(menu, iCopy);
  391.         EnableItem(menu, iClear);
  392.         EnableItem(menu, iPaste);
  393.     } else {                        /* … but we don’t use it. */
  394.         DisableItem(menu, iUndo);
  395.         DisableItem(menu, iCut);
  396.         DisableItem(menu, iCopy);
  397.         DisableItem(menu, iClear);
  398.         DisableItem(menu, iPaste);
  399.     }
  400.     
  401.     menu = GetMHandle(mWindows);                                    /* +++ */
  402.     if (gFirstWindow != NIL) {                                        /* +++ */
  403.         EnableItem(menu, iTileWindows);                                /* +++ */
  404.         EnableItem(menu, iStackWindows);                            /* +++ */
  405.     } else {                                                        /* +++ */
  406.         DisableItem(menu, iTileWindows);                            /* +++ */
  407.         DisableItem(menu, iStackWindows);                            /* +++ */
  408.     }                                                                /* +++ */
  409. }
  410.  
  411.  
  412. /*******************************************************************************
  413.  
  414.     HandleMenuCommand
  415.  
  416.     This is called when an item is chosen from the menu bar (after calling
  417.     MenuSelect or MenuKey). It performs the right operation for each command.
  418.     It is good to have both the result of MenuSelect and MenuKey go to one
  419.     routine like this to keep everything organized.
  420.  
  421. *******************************************************************************/
  422. void HandleMenuCommand(menuResult)
  423.     long        menuResult;
  424. {
  425.     short        menuID;                /* The resource ID of the selected menu */
  426.     short        menuItem;            /* The item number of the selected menu */
  427.     Str255        daName;
  428.  
  429.     menuID = HiWrd(menuResult);
  430.     menuItem = LoWrd(menuResult);
  431.     switch ( menuID ) {
  432.         case mApple:
  433.             switch ( menuItem ) {
  434.                 case iAbout:
  435.                     (void) Alert(rAboutAlert, NIL);
  436.                     break;
  437.                 default:            /* All non-About items in this menu are DAs */
  438.                     GetItem(GetMHandle(mApple), menuItem, daName);
  439.                     (void) OpenDeskAcc(daName);
  440.                     break;
  441.             }
  442.             break;
  443.         case mFile:
  444.             switch ( menuItem ) {
  445.                 case iNew:
  446.                     DoNewWindow();                                    /* +++ */
  447.                     break;
  448.                 case iClose:
  449.                     CloseAnyWindow(FrontWindow());
  450.                     break;
  451.                 case iQuit:
  452.                     gQuit = TRUE;
  453.                     break;
  454.             }
  455.             break;
  456.         case mEdit:
  457.             switch (menuItem) {
  458.                 /* Call SystemEdit for DA editing & MultiFinder */
  459.                 /* since we don’t do any Editing */
  460.                 case iUndo:
  461.                 case iCut:
  462.                 case iCopy:
  463.                 case iPaste:
  464.                 case iClear:
  465.                     (void) SystemEdit(menuItem-1);
  466.                     break;
  467.             }
  468.             break;
  469.         case mWindows:                                                /* +++ */
  470.             switch (menuItem) {                                        /* +++ */
  471.                 case iTileWindows:                                    /* +++ */
  472.                     DoTileWindows();                                /* +++ */
  473.                     break;                                            /* +++ */
  474.                 case iStackWindows:                                    /* +++ */
  475.                     DoStackWindows();                                /* +++ */
  476.                     break;                                            /* +++ */
  477.                 case iLine31:                                        /* +++ */
  478.                     break;                                            /* +++ */
  479.                 default:                                            /* +++ */
  480.                     DoSelectFromWindowsMenu(menuItem);                /* +++ */
  481.                     break;                                            /* +++ */
  482.             }                                                        /* +++ */
  483.             break;                                                    /* +++ */
  484.     }
  485.     HiliteMenu(0);        /* Unhighlight what MenuSelect or MenuKey hilited */
  486. }
  487.  
  488.  
  489. /*******************************************************************************
  490.  
  491.     CloseAnyWindow
  492.  
  493.     Close the given window in a manner appropriate for that window. If the
  494.     window belongs to a DA, we call CloseDeskAcc. For dialogs, we simply hide
  495.     the window. If we had any document windows, we would probably call either
  496.     DisposeWindow or CloseWindow after disposing of any document data and/or
  497.     controls.
  498.  
  499. *******************************************************************************/
  500. void CloseAnyWindow(WindowPtr window)
  501. {
  502.     if (IsDAWindow(window)) {
  503.         CloseDeskAcc( ( (WindowPeek) window )->windowKind );
  504.     } else if (IsDialogWindow(window)) {
  505.         HideWindow(window);
  506.     } else if (IsAppWindow(window)) {
  507.         DoCloseWindow(window);                                        /* +++ */
  508.     }
  509. }
  510.  
  511.  
  512. /*******************************************************************************
  513.  
  514.     DeathAlert
  515.  
  516.     Display an alert that tells the user an error occurred, then exit the
  517.     program. This routine is used as an ultimate bail-out for serious errors
  518.     that prohibit the continuation of the application. The error number is
  519.     used to index an 'STR#' resource so that a relevant message can be
  520.     displayed.
  521.  
  522. *******************************************************************************/
  523. void DeathAlert(short errNumber)
  524. {
  525.     short        itemHit;
  526.     Str255        theMessage;
  527.  
  528.     SetCursor(&qd.arrow);
  529.     GetIndString(theMessage, rErrorStrings, errNumber);
  530.     ParamText(theMessage, NIL, NIL, NIL);
  531.     itemHit = StopAlert(rErrorAlert, NIL);
  532.     ExitToShell();
  533. }
  534.  
  535.  
  536. /*******************************************************************************
  537.  
  538.     IsAppWindow
  539.  
  540.     Check to see if a window belongs to the application. If the window pointer
  541.     passed was NIL, then it could not be an application window. WindowKinds
  542.     that are negative belong to the system and windowKinds less than userKind
  543.     are reserved by Apple except for windowKinds equal to dialogKind, which
  544.     mean it is a dialog.
  545.  
  546. *******************************************************************************/
  547. Boolean IsAppWindow(WindowPtr window)
  548. {
  549.     short        windowKind;
  550.  
  551.     if ( window == NIL )
  552.         return false;
  553.     else {
  554.         windowKind = ((WindowPeek) window)->windowKind;
  555.         return ((windowKind >= userKind) || (windowKind == dialogKind));
  556.     }
  557. }
  558.  
  559.  
  560. /*******************************************************************************
  561.  
  562.     IsDAWindow
  563.  
  564.     Check to see if a window belongs to a desk accessory. It belongs to a DA
  565.     if the windowKind field of the window record is negative.
  566.  
  567. *******************************************************************************/
  568. Boolean IsDAWindow(WindowPtr window)
  569. {
  570.     if ( window == NIL )
  571.         return false;
  572.     else
  573.         return ( ((WindowPeek) window)->windowKind < 0 );
  574. }
  575.  
  576.  
  577. /*******************************************************************************
  578.  
  579.     IsDialogWindow
  580.  
  581.     Check to see if a window is a dialog window. We can determine this be
  582.     checking to see if the windowKind field is equal to dialogKind.
  583.  
  584. *******************************************************************************/
  585. Boolean IsDialogWindow(WindowPtr window)
  586. {
  587.     if ( window == NIL )
  588.         return false;
  589.     else
  590.         return ( ((WindowPeek) window)->windowKind == dialogKind );
  591. }
  592.  
  593.  
  594. /*******************************************************************************
  595.  
  596.     InvalidateScrollbars
  597.  
  598.     Call InvalRect on the right and bottom edges of a window. This routine is
  599.     called during the resizing of a window to take care of the scrollbar lines
  600.     and grow icon.
  601.  
  602. *******************************************************************************/
  603. void InvalidateScrollbars(WindowPtr theWindow)
  604. {
  605.     Rect    tempRect;
  606.  
  607.     SetPort(theWindow);
  608.  
  609.     tempRect = theWindow->portRect;
  610.     tempRect.left = tempRect.right - 15;
  611.     InvalRect(&tempRect);
  612.     EraseRect(&tempRect);
  613.  
  614.     tempRect = theWindow->portRect;
  615.     tempRect.top = tempRect.bottom - 15;
  616.     InvalRect(&tempRect);
  617.     EraseRect(&tempRect);
  618. }
  619.  
  620.  
  621. /*******************************************************************************
  622.  
  623.     TrapExists
  624.  
  625.     Check to see if a given trap is implemented. The recommended approach to
  626.     see if a trap is implemented is to see if the address of the trap routine
  627.     is the same as the address of the _Unimplemented trap. However, we must
  628.     also make sure that the trap is contained in the trap table on the machine
  629.     we’re running on. Not all Macintoshes have the same sized trap tables. We
  630.     call NumToolboxTraps to find out the size of the table. If the trap we are
  631.     examining falls off the end, then we treat it as automatically being
  632.     unimplemented.
  633.  
  634. *******************************************************************************/
  635. Boolean    TrapExists(short theTrap)
  636. {
  637.     TrapType    theTrapType;
  638.  
  639.     theTrapType = GetTrapType(theTrap);
  640.     if ((theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
  641.         return false;
  642.     else
  643.         return (NGetTrapAddress(_Unimplemented, ToolTrap) !=
  644.                 NGetTrapAddress(theTrap, theTrapType));
  645. }
  646.  
  647.  
  648. /*******************************************************************************
  649.  
  650.     GetTrapType
  651.  
  652.     Check the bits of a trap number to determine its type. If bit 11 is set,
  653.     it’s a toolbox trap. Otherwise, it’s an OS trap.
  654.  
  655. *******************************************************************************/
  656. TrapType    GetTrapType(short theTrap)
  657. {
  658.     if ((theTrap & 0x0800) == 0)                    /* Per D.A. */
  659.         return (OSTrap);
  660.     else
  661.         return (ToolTrap);
  662. }
  663.  
  664.  
  665. /*******************************************************************************
  666.  
  667.     NumToolboxTraps
  668.  
  669.     Find the size of the Toolbox trap table. This can be either 0x0200 or
  670.     0x0400 bytes, depending on which Macintosh we are running on. We determine
  671.     the size by taking advantage of an anomaly of the smaller trap table: any
  672.     entries that fall beyond the end of the table are mirrored back down into
  673.     the lower part. For example, on a large table, trap numbers A86E and AA6E
  674.     correspond to different routines. However, on a small table, they
  675.     correspond to the same routine. By checking the addresses of these
  676.     routines, we can determine the size of the table.
  677.  
  678. *******************************************************************************/
  679. short    NumToolboxTraps(void)
  680. {
  681.     if (NGetTrapAddress(0xA86E, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
  682.         return (0x200);
  683.     else
  684.         return (0x400);
  685. }
  686.